package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.api.service.impl.ArtificialServiceImpl;
import com.pubinfo.passbook.common.entity.TWiteoffInstance;
import com.pubinfo.passbook.common.mapper.TSourcePassbookMapper;
import com.pubinfo.passbook.common.model.dto.rule.RuleAuditChangeParam;
import com.pubinfo.passbook.common.model.dto.rule.RuleAuditParam;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.model.vo.rule.AuditDetailVo;
import com.pubinfo.passbook.common.model.vo.rule.TRuleAuditDetailVo;
import com.pubinfo.passbook.common.model.vo.rule.updateArtificialSumParam;
import com.pubinfo.passbook.common.model.vo.rule.updatePassbookSumParam;
import com.pubinfo.passbook.common.service.master.TPassbookService;
import com.pubinfo.passbook.common.service.master.TRuleAuditService;
import com.pubinfo.passbook.common.service.master.TWiteoffInstanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;

@RestController
@RequestMapping(value = "audit/manager")
@Api(tags = "待办事项管理")
public class TAuditController {

  @Resource
  private TRuleAuditService auditService;
  @Autowired
  UserInfoService userInfoService;
  @Autowired
  TPassbookService tPassbookService;
  @Autowired
  TWiteoffInstanceService tWiteoffInstanceService;
  @Autowired
  ArtificialServiceImpl artificialService;
  @Autowired
  TSourcePassbookMapper tSourcePassbookMapper;
  
  @PostMapping("select")
  @ApiOperation("查询待办列表")
  public JsonResult<MyPage<TRuleAuditDetailVo>> selectRuleAudit(@RequestBody RuleAuditParam param) {
    String currentAcct = userInfoService.getCurrentAcct();
    return JsonResult.success(new MyPage(auditService.selectRuleAudit(param, userInfoService.getCurrentUserInfo(), currentAcct)));
  }

  @PostMapping("getDetail")
  @ApiOperation("待办详情")
  public JsonResult<AuditDetailVo> getAuditDetail(String witeoffId) {
    return JsonResult.success(auditService.getAuditDetail(witeoffId));
  }

  @PostMapping("changeAudit")
  @ApiOperation("修改待办状态")
  public JsonResult<Boolean> changeAudit(@RequestBody RuleAuditChangeParam param) {
    return JsonResult.success(auditService.changeAudit(param,userInfoService.getCurrentAcct()));
  }

  @PostMapping("updateInstanceSum/{instanceId}")
  @ApiOperation("修改报销金额")
  public JsonResult<Boolean> updateInstanceSumById(BigDecimal sum, @PathVariable String instanceId) throws IOException {
    return JsonResult.success(artificialService.updateInstanceSumById(sum,instanceId,userInfoService.getCurrentAcctId()));
  }

  @PostMapping("updatePassbookSumById")
  @ApiOperation("省公司修改某张票据金额")
  public JsonResult<Boolean> updatePassbookSumById(@RequestBody updatePassbookSumParam updatePassbookSumParam) throws IOException {
    return JsonResult.success(artificialService.updatePassbookSumById(updatePassbookSumParam,userInfoService.getCurrentAcctId()));
  }

  @PostMapping("updateArtificialSumById")
  @ApiOperation("修改手工录入金额")
  public JsonResult<Boolean> updateArtificialSumById(@RequestBody updateArtificialSumParam updateArtificialSumParam) throws IOException {
    return JsonResult.success(artificialService.updateArtificialSumById(updateArtificialSumParam,userInfoService.getCurrentAcctId()));
  }
}
